package day0727API;

public class Test5 {
    public static void main(String[] args) {
        Thread t1=new Thread(){
            public void run() {
                try {
                    method();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        t1.start();


        Thread t2=new Thread(()-> {
            try {
                method();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t2.start();
    }

    /*private static synchronized  void method() throws InterruptedException {
    //静态方法上加synchronized时同步监视器对象就是字节码对应的Class对象： 获取方式   Class c=类名.class;
        System.out.println(Thread.currentThread().getName()+"进入method方法执行代码..");
        Thread.sleep(3000);
        System.out.println(Thread.currentThread().getName()+"将method方法代码执行完毕..");
        System.out.println();
    }*/
    private static   void method() throws InterruptedException {
        synchronized(Test5.class){
            System.out.println(Thread.currentThread().getName()+"进入method方法执行代码..");
            Thread.sleep(3000);
            System.out.println(Thread.currentThread().getName()+"将method方法代码执行完毕..");
            System.out.println();
        }
    }

}
